<?php
namespace App\Common\Lib\Utils\ArrayHelper;

use App\Common as com;
use App\Common\Lib\Utils\ArrayHelper\ToString as nameToString;

class ToString extends com\Lib\LibBase {

	/**
	 * @var array
	 */
	private array $data;

	private string $glue = ',';

	private bool $hasSides = false;

	/**
	 * DataCollection constructor.
	 * @param array $data
	 */
	public function __construct( array $data ) {
		$this->data = $data;
		//
		parent::__construct();
	}

	/**
	 * @param string $glue
	 * @return $this
	 */
	public function glue( string $glue = ',' ):self {
		$this->glue = $glue;
		//
		return $this;
	}

	/**
	 * @param bool $hasSides
	 * @return $this
	 */
	public function hasSides( bool $hasSides = true ):self {
		$this->hasSides = $hasSides;
		//
		return $this;
	}

	/**
	 * @param string $default
	 * @return string
	 */
	public function get( string $default = '' ):string {
		return com\Lib\Fun\Array_::toStr( $this->data, [
			'glue' => $this->glue,
			'has_sides' => $this->hasSides,
			'default' => $default,
		] );
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param array $data
	 * @return $this
	 */
	public static function new( array $data ):self {
		return self::make( ...func_get_args() );
	}

}
